/**
 * 社区数据操作
 */
 var AV = require('leanengine');
 var lean = require('../../../base/lean.js');
 var Property = require('./Property')

// 根据社区名称字段模糊搜索
exports.community_search = function(communtiyName,callback) {
    var cqlString = "select * from Community where c_name like '%" + communtiyName + "%'"
    lean.cql(cqlString,function(data){
        // 查询社区所在物业
        var communityList = data.results
        if(communityList != ''){
            var backData = []
            callback(communityList)

        }else{
            callback(communityList)
        }

    });
}


// 查询社区名称
exports.community_find = function(name,callback) {
    var cqlString = "select * from Community where c_name = '" + name + "' limit 0,1"
    lean.cql(cqlString,function(data){
        callback(data.results)
    })
}

// 获取社区详情和设备列表
exports.community_details = function(communityId,callback) {
    // 社区详情
    var cqlString_communityDetails = "select * from Community where objectId = '" + communityId + "' limit 0,1";
    var community_details = {};
    lean.cql(cqlString_communityDetails,function(data){
        var community = data.results;

        // 设备列表
        var cqlString_deviceList = "select * from Device where d_c=pointer('Community','" + communityId + "') order by d_id";
        lean.cql(cqlString_deviceList,function(deviceList){
            var deviceList = deviceList.results;
            community_details.community = community;
            community_details.deviceList = deviceList;
            callback(community_details);
        })
    })
}
